﻿#include "datamodel.h"
#include <QVariant>
#include <QDebug>

DataModel::DataModel(QObject *parent)
    : QAbstractListModel{parent}
{

}

int DataModel::rowCount(const QModelIndex &parent) const
{
    return 3; //list.count();
}

QVariant DataModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();
    switch(role) {
    case DataModel::one:
        return "111";
    case DataModel::two:
        return "222";
    case DataModel::three:
        return "333";
    case DataModel::total:
        return QVariant::fromValue(2);
    default:
        return "444";
    }
    return QVariant();
}

QHash<int, QByteArray> DataModel::roleNames() const
{
    // value这些字符串名称是给qml使用的，也可以不用；key只是方便定位
    QHash<int, QByteArray> d;
    d[one] = "one";
    d[two] = "two";
    d[three] = "three";
    d[total] = "total";
    return d;
}
